package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class LoginDemo1 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入用户名");
        String getUsername=sc.nextLine();
        System.out.println("请输入密码");
        String getPassword=sc.nextLine();

        try (
                Connection con=DBUtil.getConnection();
                ){
            Statement stm=con.createStatement();
            String sql = "SELECT username,password FROM userinfo " +
                         " WHERE username='"+getUsername+"'"+
                         "AND password='"+getPassword+"'";
            System.out.println(sql);
            ResultSet rs=stm.executeQuery(sql);
            if (rs.next()){
                System.out.println("登录成功");
            }else {
                System.out.println("登录失败");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }
}
